package org.finalministry.objects.address;

import java.util.Calendar;

import javax.persistence.Entity;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.finalministry.objects.FlagTagNoteAbleBase;
import org.finalministry.utils.geo.GeoUtils;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;

/**
 * A address represents a point on the map, but not obligatory a person. It's
 * just a address with maybe a geolocation.
 * 
 * @author admin
 * 
 */
@Entity
@XmlRootElement
public class Address extends FlagTagNoteAbleBase {

	private String street;
	private String housenumber;
	private String postalcode;
	private String city;
	private Country country;

	@XmlTransient
	@JsonIgnore
	private Geometry coordinate;
	private Calendar created;

	public Address() {

	}

	public Address(String street, String housenumber, String postalcode, String city, Country country, Geometry coordinate) {
		super();
		this.street = street;
		this.housenumber = housenumber;
		this.postalcode = postalcode;
		this.city = city;
		this.setCountry(country);
		this.coordinate = coordinate;
		this.created = Calendar.getInstance();
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getHousenumber() {
		return housenumber;
	}

	public void setHousenumber(String housenumber) {
		this.housenumber = housenumber;
	}

	public String getPostalcode() {
		return postalcode;
	}

	public void setPostalcode(String postalcode) {
		this.postalcode = postalcode;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	@XmlTransient
	public Geometry getCoordinate() {
		return coordinate;
	}

	public void setCoordinate(Geometry coordinate) {
		this.coordinate = coordinate;
	}

	public void setNewCoordinate(double x, double y) {
		this.coordinate = GeoUtils.getPointFromCoordinate(new Coordinate(x, y));
	}

	public Calendar getCreated() {
		return created;
	}

	public void setCreated(Calendar created) {
		this.created = created;
	}

	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	@Override
	public String toString() {

		return street + " " + housenumber + ", " + postalcode + " " + city;
	}
}
